import 'dart:io';

import 'package:core_package/core_package.dart';
import 'package:flutter/material.dart';
import 'package:flutter_app_unionad/core/configuration.dart';
import 'package:provider/provider.dart';

enum PagesManagerType {
  app,
  login,
  launch,
}

class PagesManagerViewModel extends ChangeNotifier {
  PagesManagerViewModel() {
    _type = (UserCacheUil.getInt(Configuration.userId) != null && UserCacheUil.getInt(Configuration.userId) != 0)
        ? PagesManagerType.app
        : PagesManagerType.login;
    if (_type == PagesManagerType.app ) {
      _type = PagesManagerType.launch;
    }
  }

  PagesManagerType _type = PagesManagerType.login;

  set type(PagesManagerType type) {
    _type = type;
    notifyListeners();
  }

  PagesManagerType get type {
    // _type = UserCacheUil.getInt(Configuration.userId) != null ? PagesManagerType.app : PagesManagerType.login;
    return _type;
  }

  static void updateType(BuildContext context, PagesManagerType type) {
    Provider.of<PagesManagerViewModel>(context, listen: false).type = type;
  }

  static void splashUpdateType(BuildContext context) {
    PagesManagerType type =
        (UserCacheUil.getInt(Configuration.userId) != null && UserCacheUil.getInt(Configuration.userId) != 0)
            ? PagesManagerType.app
            : PagesManagerType.login;

    Provider.of<PagesManagerViewModel>(context, listen: false).type = type;
  }
}
